<!--
 * @Descripttion: 提现记录
 * @Author: xiao li
 * @Date: 2020-07-06 12:17:07
 * @LastEditors: xiao li
 * @LastEditTime: 2021-04-29 14:20:12
-->
<template>
    <div class="lb-sys-sproconfig">
        <top-nav></top-nav>
        <div class="page-main">
        <div class="page-search-form">
          <el-form @submit.native.prevent :inline="true" :model="searchForm" ref="searchForm">
            <el-form-item label="状态" prop="status">
                <el-select  @change="typeChange" v-model="searchForm.status" placeholder="请选择">
                    <el-option
                    v-for="item in typeOptions"
                    :key="item.id"
                    :label="item.name"
                    :value="item.id"
                    >
                    </el-option>
                </el-select>
            </el-form-item>
            <el-form-item label="员工姓名/昵称" prop="name">
              <el-input v-model="searchForm.name" placeholder="请输入员工姓名/昵称"></el-input>
            </el-form-item>
            <el-form-item>
              <lb-button size="medium" type="primary" icon="el-icon-search" style="margin-right:5px" @click="getTableDataList(1)">{{$t('action.search')}}</lb-button>
              <lb-button size="medium" icon="el-icon-refresh-left" style="margin-right:5px" @click="resetForm('searchForm')">{{$t('action.reset')}}</lb-button>
            </el-form-item>
          </el-form>
        </div>
            <el-table
            v-loading="loading"
            :data="tableData"
          :header-cell-style="{background:'#f5f7fa',color:'#606266'}"
            style="width: 100%">
            <el-table-column
              prop="id"
              label="ID"
              width='100'>
            </el-table-column>
            <el-table-column
              prop="staff_name"
              label="员工姓名">
            </el-table-column>
            <el-table-column
              prop="nickName"
              label="员工昵称">
            </el-table-column>
            <el-table-column
              prop="true_price"
              label="提现金额">
              <template slot-scope="scope">
                <div>{{scope.row.true_price}}元</div>
              </template>
            </el-table-column>
            <el-table-column
              prop="create_time"
              label="申请时间">
              <template slot-scope="scope">
                <p>{{scope.row.create_time | handleTime(1)}}</p>
                <p>{{scope.row.create_time | handleTime(2)}}</p>
              </template>
            </el-table-column>
            <el-table-column
              prop="status"
              label="状态">
              <template slot-scope="scope">
                <div>{{scope.row.status === 1 ? '未审核':scope.row.status === 2 ? '已通过': '已驳回'}}</div>
              </template>
            </el-table-column>
            <el-table-column
              prop="create_time"
              label="到账时间">
              <template slot-scope="scope">
                <div v-if="scope.row.status === 2">
                  <p>{{scope.row.create_time | handleTime(1)}}</p>
                  <p>{{scope.row.create_time | handleTime(2)}}</p>
                </div>
                <div v-else>--</div>
              </template>
            </el-table-column>
            <el-table-column
              label="操作">
                <template slot-scope="scope">
                  <div class="table-operate">
                    <lb-button size='mini' plain type='primary' @click="toPassPeject(scope.row.id,1)" v-if="scope.row.status === 1">{{$t('action.pass')}}</lb-button>
                    <lb-button size='mini' plain type='danger' @click="toPassPeject(scope.row.id,2)" v-if="scope.row.status === 1">{{$t('action.reject')}}</lb-button>
                  </div>
                </template>
            </el-table-column>
          </el-table>
          <lb-page
          :batch='false'
          :page='searchForm.page'
          :pageSize='searchForm.limit'
          :total='total'
          @handleSizeChange='handleSizeChange'
          @handleCurrentChange='handleCurrentChange'
          >
          </lb-page>
        </div>
    </div>
</template>

<script>
export default {
  data () {
    return {
      typeOptions: [{
        id: 0,
        name: '全部'
      }, {
        id: 1,
        name: '未审核'
      }, {
        id: 2,
        name: '已通过'
      }, {
        id: 3,
        name: '已驳回'
      }],
      searchForm: {
        status: 0,
        name: '',
        limit: 10,
        page: 1
      },
      total: 0,
      tableData: []
    }
  },
  created () {
    this.getTableDataList()
  },
  methods: {
    resetForm (name) {
      this.$refs[name].resetFields()
      this.getTableDataList(1)
    },
    handleSizeChange (val) {
      this.searchForm.limit = val
      this.handleCurrentChange(1)
    },
    handleCurrentChange (val) {
      this.searchForm.page = val
      this.getTableDataList()
    },
    async getTableDataList (flag) {
      if (flag) this.searchForm.page = 1
      this.loading = true
      let {searchForm} = this
      let {code, data} = await this.$api.reductionWalletList(searchForm)
      this.loading = false
      if (code !== 200) return
      this.tableData = data.data
      this.total = data.total
    },
    async toPassPeject (id, type) {
      let confirmText = this.$t(type === 1 ? 'tips.confirmPass' : 'tips.confirmNoPass')
      this.$confirm(confirmText, this.$t('tips.reminder'), {
        confirmButtonText: this.$t('action.comfirm'),
        cancelButtonText: this.$t('action.cancel'),
        type: 'warning'
      }).then(() => {
        this.toConfirm(id, type)
      }).catch(() => {

      })
    },
    async toConfirm (id, type) {
      let methodModel = type === 1 ? 'reductionPass' : 'reductionNoPass'
      let {code} = await this.$api[methodModel]({id})
      if (code !== 200) return
      this.$message.success(this.$t('tips.successOper'))
      this.tableData = []
      this.getTableDataList()
    }
  },
  filters: {
    handleTime (val, type) {
      let time = type === 1 ? moment(val * 1000).format('YYYY-MM-DD') : type === 2 ? moment(val * 1000).format('HH:mm:ss') : moment(val * 1000).format('YYYY-MM-DD HH:mm:ss')
      return time
    }
  }
}
</script>

<style lang="scss" scoped>
    .el-input,
    .el-select{
      width: 200px;
    }
</style>
